#include <iostream>
#include <vector>
using namespace std;

int cnt = 0;
int n = 0;
void dfs(const vector<int>& v, vector<bool>& visited, int& res)
{
    if (cnt == n) {
        ++res;
        return;
    }
    for (int i = 1;i <= n;++i)
    {
        if (visited[i]) {
            continue;
        }
        if (visited[v[i]]) //剪枝
        {
            return;
        }
        ++cnt;
        visited[i] = true;
        dfs(v, visited, res);
        --cnt;
        visited[i] = false;
    }
}
int main()
{
    cin >> n;
    vector<int> v(n+1);
    for (int i = 1;i <= n;++i)
    {
        cin >> v[i];
    }
    vector<bool> visited(n+1,false);
    int res = 0;
    dfs(v, visited, res);
    cout << res;
}